<?php

/**
 * @filename swoole_process2.php 
 * @encoding UTF-8 
 * @author  fwz 
 * @datetime 2018-6-12  16:33:51
  */



//swoole 进程数量

$worker = [];   //进程数组
$worker_num = 3;  // 创建进程的数据量


//创建启动进程
for($i=0;$i<$worker_num;$i++){
    $process = new swoole_process("doProcess");  //创建单独进程
    $pid = $process->start(); //启动进程，并获取进程id
    $worker[$pid] = $process;
}


//创建进程执行函数
function doProcess(swoole_process $process){
    $process->write("PID : $process->pid"); //子进程写入信息
    
    echo "write ： $process->pid $process->callback  \n";
}

//添加进程时间，向每一个子进程添加，需要执行的动作
foreach($worker as $process){
    //添加
    swoole_event_add($process->pipe,function($pipe) use($process){
        $data = $process->read();
        echo "read   $data  \n";
    });
}


